<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>TemplateSimple</title>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
  tex2jax: { inlineMath: [['$','$'], ['\\(','\\)']] },
  TeX: { equationNumbers: { autoNumber: 'all' } }
});
</script>
<script type="text/javascript" async src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML"></script>
<style>
body > * {
  max-width: 1000px;
}
body {
  font-family: "Roboto Condensed", sans-serif;
  padding-left: 7.5em;
  padding-right: 7.5em;
}
pre, code {
  max-width: 60em;
  font-family: monospace;
}
pre.oct-code {
  border: 1px solid Grey;
  padding: 5px;
}
pre.oct-code-output {
  margin-left: 2em;
}
span.comment {
  color: ForestGreen;
}
span.keyword {
  color: Blue;
}
span.string {
  color: DarkOrchid;
}
footer {
  margin-top: 2em;
  font-size: 80%;
}
a, a:visited {
  color: Blue;
}
h2 {
  font-family: "Roboto Condensed", serif;
  margin-top: 1.5em;
}
h2 a, h2 a:visited {
  color: Black;
}
</style>
</head>
<body>
<p><b>Defining parameters</b></p><pre class="oct-code"><span class="comment">% Choosing tire</span>
TireModel = TirePacejka();
<span class="comment">% Choosing vehicle</span>
VehicleModel = VehicleSimpleNonlinear();</pre><p>In this case, no parameter is defined. So, the default values are used.</p><p>Now, we have two variables defined. The first one is the tire model (Pacejka) and the second one is the vehicle model (Vehicle simple nonlinear).</p><p>The System is completely defined once we attribute the chosen tire model to the vehicle object.</p><pre class="oct-code">VehicleModel.tire = TireModel;</pre><p>Choosing the simulation time span</p><pre class="oct-code">T = 6;                              <span class="comment">% Total simulation time [s]</span>
resol = 50;                         <span class="comment">% Resolution</span>
TSPAN = 0:T/resol:T;                <span class="comment">% Time span [s]</span>
</pre><p>To define a simulation object (simulator) the arguments must be the vehicle object and the time span. The default parameters of the simulation object can be found in <a href="api/Simulator.html">Simulator</a>.</p><pre class="oct-code">simulator = Simulator(VehicleModel, TSPAN);</pre><p>Changing initial conditions of the simulation object</p><pre class="oct-code">simulator.ALPHAT0 = -0.2;           <span class="comment">% Initial side slip angle [rad]</span>
simulator.dPSI0 = 0.7;              <span class="comment">% Initial yaw rate [rad/s]</span>
</pre><p><b>Run simulation</b></p><pre class="oct-code">simulator.Simulate();</pre><p><b>Results</b></p><p>The time history of each state is stored in separate variables. Retrieving states</p><pre class="oct-code">XT = simulator.XT;
YT = simulator.YT;
PSI = simulator.PSI;
VEL = simulator.VEL;
ALPHAT = simulator.ALPHAT;
dPSI = simulator.dPSI;</pre><p><b>Plotting the states</b></p><pre class="oct-code">f1 = figure(1);
grid on ; box on
plot(TSPAN,XT,<span class="string">'linewidth'</span>,1)
xlabel(<span class="string">'time [s]'</span>)
ylabel(<span class="string">'Distance in the x direction [m]'</span>)</pre><img width="500" src="../illustrations/plot/TemplateSimpleFig1.svg" alt="../illustrations/plot/TemplateSimpleFig1.svg"><pre class="oct-code">f2 = figure(2);
grid on ; box on
plot(TSPAN,YT,<span class="string">'linewidth'</span>,1)
xlabel(<span class="string">'time [s]'</span>)
ylabel(<span class="string">'Distance in the y direction [m]'</span>)</pre><img width="500" src="../illustrations/plot/TemplateSimpleFig2.svg" alt="../illustrations/plot/TemplateSimpleFig2.svg"><pre class="oct-code">f3 = figure(3);
grid on ; box on
plot(TSPAN,PSI,<span class="string">'linewidth'</span>,1)
xlabel(<span class="string">'time [s]'</span>)
ylabel(<span class="string">'Yaw angle [rad]'</span>)</pre><img width="500" src="../illustrations/plot/TemplateSimpleFig3.svg" alt="../illustrations/plot/TemplateSimpleFig3.svg"><pre class="oct-code">f4 = figure(4);
grid on ; box on
plot(TSPAN,VEL,<span class="string">'linewidth'</span>,1)
xlabel(<span class="string">'time [s]'</span>)
ylabel(<span class="string">'Velocity [m/s]'</span>)</pre><img width="500" src="../illustrations/plot/TemplateSimpleFig4.svg" alt="../illustrations/plot/TemplateSimpleFig4.svg"><pre class="oct-code">f5 = figure(5);
grid on ; box on
plot(TSPAN,ALPHAT,<span class="string">'linewidth'</span>,1)
xlabel(<span class="string">'time [s]'</span>)
ylabel(<span class="string">'Vehicle slip angle [rad/s]'</span>)</pre><img width="500" src="../illustrations/plot/TemplateSimpleFig5.svg" alt="../illustrations/plot/TemplateSimpleFig5.svg"><pre class="oct-code">f6 = figure(6);
grid on ; box on
plot(TSPAN,dPSI,<span class="string">'linewidth'</span>,1)
xlabel(<span class="string">'time [s]'</span>)
ylabel(<span class="string">'Yaw rate [rad/s]'</span>)</pre><img width="500" src="../illustrations/plot/TemplateSimpleFig6.svg" alt="../illustrations/plot/TemplateSimpleFig6.svg"><p><b>Frame and animation</b></p><pre class="oct-code">g = Graphics(simulator);

g.Frame();
g.Animation();</pre><img width="800" src="../illustrations/frame/TemplateSimpleFrame.svg" alt="../illustrations/frame/TemplateSimpleFrame.svg"><img src="../illustrations/animation/TemplateSimpleAnimation.gif" alt="../illustrations/animation/TemplateSimpleAnimation.gif">
<footer><hr><a href="http://www.octave.org">Published with GNU Octave 4.2.1</a></footer>
<!--
##### SOURCE BEGIN #####
%%
% *Defining parameters*

% Choosing tire
TireModel = TirePacejka();
% Choosing vehicle
VehicleModel = VehicleSimpleNonlinear();

%%
% In this case, no parameter is defined. So, the default values are used.
%
% Now, we have two variables defined. The first one is the tire model (Pacejka) and the second one is the vehicle model (Vehicle simple nonlinear).
%
% The System is completely defined once we attribute the chosen tire model to the vehicle object.

VehicleModel.tire = TireModel;

%%
% Choosing the simulation time span

T = 6;                              % Total simulation time [s]
resol = 50;                         % Resolution
TSPAN = 0:T/resol:T;                % Time span [s]

%%
% To define a simulation object (simulator) the arguments must be the vehicle object and the time span. The default parameters of the simulation object can be found in <api/Simulator.html Simulator>.

simulator = Simulator(VehicleModel, TSPAN);

%%
% Changing initial conditions of the simulation object

simulator.ALPHAT0 = -0.2;           % Initial side slip angle [rad]
simulator.dPSI0 = 0.7;              % Initial yaw rate [rad/s]

%%
% *Run simulation*
%

simulator.Simulate();

%%
% *Results*
%
% The time history of each state is stored in separate variables. Retrieving states

XT = simulator.XT;
YT = simulator.YT;
PSI = simulator.PSI;
VEL = simulator.VEL;
ALPHAT = simulator.ALPHAT;
dPSI = simulator.dPSI;

%%
% *Plotting the states*

f1 = figure(1);
grid on ; box on
plot(TSPAN,XT,'linewidth',1)
xlabel('time [s]')
ylabel('Distance in the x direction [m]')

%%
% <<../illustrations/plot/TemplateSimpleFig1.svg>>

f2 = figure(2);
grid on ; box on
plot(TSPAN,YT,'linewidth',1)
xlabel('time [s]')
ylabel('Distance in the y direction [m]')

%%
% <<../illustrations/plot/TemplateSimpleFig2.svg>>

f3 = figure(3);
grid on ; box on
plot(TSPAN,PSI,'linewidth',1)
xlabel('time [s]')
ylabel('Yaw angle [rad]')

%%
% <<../illustrations/plot/TemplateSimpleFig3.svg>>

f4 = figure(4);
grid on ; box on
plot(TSPAN,VEL,'linewidth',1)
xlabel('time [s]')
ylabel('Velocity [m/s]')

%%
% <<../illustrations/plot/TemplateSimpleFig4.svg>>

f5 = figure(5);
grid on ; box on
plot(TSPAN,ALPHAT,'linewidth',1)
xlabel('time [s]')
ylabel('Vehicle slip angle [rad/s]')

%%
% <<../illustrations/plot/TemplateSimpleFig5.svg>>

f6 = figure(6);
grid on ; box on
plot(TSPAN,dPSI,'linewidth',1)
xlabel('time [s]')
ylabel('Yaw rate [rad/s]')

%%
% <<../illustrations/plot/TemplateSimpleFig6.svg>>

%%
% *Frame and animation*

g = Graphics(simulator);

g.Frame();
g.Animation();

%%
% <<../illustrations/frame/TemplateSimpleFrame.svg>>
%
% <<../illustrations/animation/TemplateSimpleAnimation.gif>>
%
##### SOURCE END #####
-->
</body>
</html>
